package com.erps.sys.rest;

import java.util.List;
import java.util.Map;

import com.erps.CommonUtils.StringEx;
import com.erps.db.DBManager;
import com.hmkj.entity.vo.ersp_achievement_vo;

public class ErspAchievementRest {

	public PageData Query(String cOrgID, int iPageNO, int iPageSize,
			String cSort) {
		String cWhereParm = "";
		StringBuffer sql = new StringBuffer();
		sql.append(" select count(1) ");
		sql.append(" from ersp_achievement ");

		// 添加Where条件
		if (StringEx.getStr(cWhereParm).length() > 0) {
			sql.append(cWhereParm);
		}
		String cOrderBy = " order by last_update_time desc ";
		int iRowCount = StringEx.getInt(DBManager.GetStrValue(sql.toString()));
		int iPageCount = (int) Math.ceil(iRowCount / (double) iPageSize);
		if (iPageNO < 0)
			iPageNO = 1;
		else if (iPageNO > iPageCount)
			iPageNO = iPageCount;

		sql.setLength(0);
		sql.append(" select * ");
		sql.append(" from ersp_achievement");

		List<Map<String, String>> dtRows = DBManager.QueryData(sql.toString(),
				cOrderBy, iPageNO, iPageSize);
		PageData ret = new PageData();
		ret.setRowcount(iRowCount);
		ret.setPagecount(iPageCount);
		ret.setPageno(iPageNO);

		int iLength = (dtRows == null) ? 0 : dtRows.size();
		for (int i = 0; i < iLength; i++) {
			Map<String, String> vo = dtRows.get(i);
			ersp_achievement_vo voRes = new ersp_achievement_vo();
			voRes.setId(StringEx.getMapVal(vo, "id"));
			voRes.setOrg_id(StringEx.getMapVal(vo, "org_id"));
			voRes.setArch_status((short) StringEx.getInt(StringEx.getMapVal(vo,
					"arch_status")));
			voRes.setClick(StringEx.getInt(StringEx.getMapVal(vo, "click")));
			voRes.setHost_unit(StringEx.getMapVal(vo, "host_unit"));
			voRes.setLast_update_time((long) StringEx.getInt(StringEx
					.getMapVal(vo, "last_update_time")));
			voRes.setName(StringEx.getMapVal(vo, "name"));
			voRes.setContent(StringEx.getMapVal(vo, "content"));
			voRes.setReception_unit(StringEx.getMapVal(vo, "reception_unit"));
			voRes.setOrg_name(new ErspSysOrgRest().FindOne(voRes.getId())
					.getOrg_name());
			voRes.setImageurl("/dfs/201608/" + voRes.getId() + ".png");
			// http://125.46.61.66:8080/html/images/1121313.png

			ret.getKeylist().add(voRes);
		}
		return ret;
	}
}
